<div id="LAY_app_body" class="layui-body">
    <div class="layadmin-tabsbody-item layui-show">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-warm" lay-tree-action="reload">取消</button>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-card-body">
                    <div id="tree" class="demo-tree-more"></div>
                </div>

                <form class="layui-form layui-form-pane" lay-filter="form">
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <input type="hidden" name="id"  >
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">提交</button>
                            <a href="{:url('roleList')}" class="layui-btn layui-btn-primary">返回</a>
                        </div>
                    </div>
                </form>


            </div>
        </div>
    </div>
</div>
<script type="text/html" id="action" lay-filter="action">
    <a  class="layui-btn layui-btn-sm" lay-event="rule" href="{:url('groupAccess')}?id={{d.id}}">设置权限</a>
    <a  class="layui-btn layui-btn-sm " lay-event="edit">>编辑</a>
    <a  class="layui-btn layui-btn-sm layui-btn-danger " lay-event="del">删除</a>
</script>

<div id="add_role_from" style="padding: 20px 30px 0 0;" style="display: none">
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <input type="text" id="rolename" name="rolename" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
        </div>
    </div>


</div>

<script type="text/javascript">
    layui.use(['form','tree','util','form'], function () {
        var $ = layui.jquery,
            util = layui.util,
            form = layui.form,
            tree = layui.tree;
        var menuTree = {:json_encode($menuTree)};
        tree.render({
            elem: '#tree'
            ,data:menuTree
            ,showCheckbox: true
            ,id: 'treebox'
            ,showLine:true
            ,isJump: false
    });
        //按钮事件
        util.event('lay-tree-action', {
            // getChecked: function (othis) {
            //     var checkedData = tree.getChecked('treebox'); //获取选中节点的数据
            // }
            // , setChecked: function () {
            //     tree.setChecked('treebox', idList); //勾选指定节点
            // }
             reload: function () {
                //重载实例
                tree.reload('treebox', {});
            }
        })

        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var data  = tree.getChecked('treebox');
            $.post("/manage/Role/groupSetAccess", {rules:data,group_id:'{$groupId}'}, function (res) {
                layer.close(loading);
                if (res.code == 0) {
                    layer.msg(res.message, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.message, {time: 1800, icon: 2});
                }
            });
        });
    });


</script>
